﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZSPG_JGHZInfoControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            MPPersistence Persistence1 = (MPPersistence)FindControl("Persistence1");
            Panel panel1 = (Panel)FindControl("panel1");
            if (!base.Page.IsPostBack)
            {
                Persistence1.Table = "ZS_PGJGHZ";
                Persistence1.Key = "ID";
                Persistence1.KeyValue = HttpContext.Current.Request["ID"];
                Persistence1.ConnStr = _EluZSDataProvider.GetConnectionString();
            }
            Persistence1.BindControl = panel1;
            BindData();
            IsLookPerson();
        }

        private void IsLookPerson()
        {
            string sql = "Select rolename from zs_role where id in (Select roleid from zs_user_in_role where userid = '" + userid + "')";
            DataTable dt = _EluZSDataProvider.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["rolename"].ToString().Equals("查看人员"))
                    {
                        Button btn_Insert = (Button)FindControl("btn_Insert");
                        btn_Insert.Visible = false;
                    }
                }
            }
        }


        protected override void OnPreRender(EventArgs e) {
            base.OnPreRender(e);
            
            Label 项目名称 = (Label)FindControl("项目名称");
            Label 征收决定号 = (Label)FindControl("征收决定号");
            Label 档案号 = (Label)FindControl("档案号");
            Label 评估委托单位 = (Label)FindControl("评估委托单位");
            Label 征收实施单位 = (Label)FindControl("征收实施单位");

            Label 评估机构 = (Label)FindControl("评估机构");
            Label 项目地址 = (Label)FindControl("项目地址");
            Label 区属 = (Label)FindControl("区属");
            Label 级别 = (Label)FindControl("级别");
            Label 征收范围 = (Label)FindControl("征收范围");

            TextBox txtPID = (TextBox)FindControl("txtPID");
            string PNID = HttpContext.Current.Request["PID"];

            if (!string.IsNullOrEmpty(PNID))
            {
                txtPID.Text = PNID;
                EluZSProvider.Prono prono = _EluZSDataProvider.GetProno(PNID);
                征收决定号.Text = prono.征收许可证号;
                评估机构.Text = prono.已通过征收评估机构;
                string pid = prono.PID;
                if (!string.IsNullOrEmpty(pid)) {
                    EluZSProvider.Project project = _EluZSDataProvider.GetProjectXX(pid);
                    项目名称.Text = project.项目名称;
                    评估委托单位.Text = project.评估委托单位;
                    征收实施单位.Text = project.征收实施单位;
                    征收范围.Text = project.征收范围;
                    区属.Text = project.区属;
                    级别.Text = project.级别;
                    项目地址.Text = project.项目地址;
                }
            }
        }
        protected void BindData() {
            Button btn_Insert = (Button)FindControl("btn_Insert");
            Button btnUpload = (Button)FindControl("btnUpload");
            btn_Insert.Click += new EventHandler(btn_Insert_Click);
            btnUpload.Click += new EventHandler(btnUpload_Click);
        }

        protected void btnUpload_Click(object sender, EventArgs e)
        {
            MPPersistence Persistence1 = (MPPersistence)FindControl("Persistence1");
            if (!string.IsNullOrEmpty(Persistence1.KeyValue)) {
                string strScript = string.Format("<script>OpenFileUpload('{0}','{1}','{2}');</script>",
                Persistence1.KeyValue, base.Page.Request["ID"].Trim(), base.Page.Request["PID"].Trim());
                Page.ClientScript.RegisterStartupScript(this.GetType(), "opennew", strScript);
            }
        }

        protected void btn_Insert_Click(object sender, EventArgs e)
        {
            MPPersistence Persistence1 = (MPPersistence)FindControl("Persistence1");
            Persistence1.Update();
            string strPID = base.Page.Request["PID"];
            if (_EluZSDataProvider.CkFileCount(strPID, "4")) { _EluZSDataProvider.UpdateFileCS(strPID, "4"); }
            HttpContext.Current.Response.Redirect("ZSPG_JGHZInfo.aspx?ID=" + Persistence1.KeyValue + "&PID=" + base.Page.Request["PID"]);
        }
    }
}


